from datetime import date, datetime
from typing import List, Optional
from pydantic import BaseModel


class PredictionData(BaseModel):
    """单个预测数据点"""
    id: int
    dt: date
    t_idx: int
    dtm: datetime
    model: str
    pred_val: float
    created_at: datetime
    
    class Config:
        from_attributes = True


class PredictionResponse(BaseModel):
    """单日预测响应"""
    date: date
    predictions: List[PredictionData]


class MultiDayPredictionResponse(BaseModel):
    """多日预测响应"""
    start_date: date
    end_date: date
    day_count: int
    predictions: List[PredictionData]
    models_included: List[str]


class LoadDataResponse(BaseModel):
    """负荷数据响应"""
    id: int
    dt: date
    t_idx: int
    dtm: datetime
    load_val: float
    created_at: datetime
    
    class Config:
        from_attributes = True


class WeatherDataResponse(BaseModel):
    """气象数据响应"""
    id: int
    dt: date
    t_max: Optional[float] = None
    t_min: Optional[float] = None
    t_app_max: Optional[float] = None
    t_app_min: Optional[float] = None
    prec_sum: Optional[float] = None
    rain_sum: Optional[float] = None
    show_sum: Optional[float] = None
    snow_sum: Optional[float] = None
    prec_hrs: Optional[float] = None
    wcode: Optional[int] = None
    sun_dur: Optional[float] = None
    uv_max: Optional[float] = None
    ws_max: Optional[float] = None
    wg_max: Optional[float] = None
    wd_dom: Optional[int] = None
    sw_rad: Optional[float] = None
    et0: Optional[float] = None
    snowd_max: Optional[float] = None
    created_at: datetime
    
    class Config:
        from_attributes = True


class ModelEvalResponse(BaseModel):
    """模型评估响应"""
    id: int
    model: str
    train_dt: date
    mae: Optional[float] = None
    rmse: Optional[float] = None
    mape: Optional[float] = None
    r2: Optional[float] = None
    max_err: Optional[float] = None
    created_at: datetime
    
    class Config:
        from_attributes = True


class ApiResponse(BaseModel):
    """通用API响应格式"""
    code: int = 200
    message: str = "success"
    data: Optional[dict] = None